{% extends 'admin/public/base.html' %}

{% block con-header %}
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading">
                <span class="am-icon-user page-header-heading-icon"></span> 
                商品列表 
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block con-body %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
               
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>



                <form>
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="type" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                              <option {% if request.GET.type == 'all' %} selected {% endif %} value="all">全部条件</option>
                              <option {% if request.GET.type == 'title' %} selected {% endif %} value="title">商品标题</option>
                              <option {% if request.GET.type == 'typeid' %} selected {% endif %} value="typeid">商品类型</option>
                              <option {% if request.GET.type == 'storage' %} selected {% endif %} value="storage">库存</option>
                              <option {% if request.GET.type == 'price' %} selected {% endif %} value="price">价格</option>
                              <option {% if request.GET.type == 'status' %} selected {% endif %} value="status">状态</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input name="keywords" type="text" class="am-form-field" value="{{ request.GET.keywords }}">
                            <span class="am-input-group-btn">
                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                            </span>
                        </div>
                    </div>
                </form>



                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>商品缩略图</th>
                                    <th>ID</th>
                                    <th>商品标题</th>
                                    <th>商品分类</th>                                    
                                    <th>价格</th>
                                    <th>库存</th>
                                    <th>点击量</th>
                                    <th>购买数</th>
                                    <th>添加时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for v in glist %}
                                <tr class="gradeX">
                                    <td>
                                        <img src="{{ v.pic }}" class="tpl-table-line-img" alt="">
                                    </td>
                                    <td class="am-text-middle">{{ v.id }}</td>
                                    <td class="am-text-middle">{{ v.title }}</td>
                                    <td class="am-text-middle">{{ v.typeid.name }}</td>
                                    <td class="am-text-middle">{{ v.price }}</td>
                                    <td class="am-text-middle">{{ v.storage }}</td>
                                    <td class="am-text-middle">{{ v.clicknum }}</td>
                                    <td class="am-text-middle">{{ v.num }}</td>
                                    <td class="am-text-middle">{{ v.addtime|date:'Y-m-d H:i:s' }}</td>
                                    <td class="am-text-middle">
                                        <select uid="{{ v.id }}" class="user_status_save" style="color:#000">

                                            <option value="0" {% if v.status == 0 %} selected {% endif %}>下架</option>
                                            <option value="1" {% if v.status == 1 %} selected {% endif %}>新品</option>
                                            <option value="2" {% if v.status == 2 %} selected {% endif %}>热卖</option>
                                        </select>
                                    </td>
                                   
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="{% url 'admin_goods_edit' v.id %}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="{% url 'admin_goods_del'%}" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                             
                           </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                            {% load pagetag %}

                            {% showpage glist.paginator.num_pages request %}
                                
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $('.user_status_save').change(function(){
        // 获取当前选择的状态
        s = $(this).val()
        // 获取用户id
        id = $(this).attr('uid')
        // 发送ajax执行修改
        $.get('{% url "admin_goods_status" %}',{uid:id,status:s})
    })




    $('.tpl-table-black-operation-del').click(function(){
        a = $(this)
        gid = $(this).parents('.gradeX').find('select').attr('uid')
        // console.log(gid)

        $.get('{% url "admin_goods_del" %}',{gid:gid},function(){
            a.parents('tr').remove()
        })
        return false;
    })

</script>
{% endblock %}